<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: acer
  Date: 2019/1/17
  Time: 18:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui-2.4/layui-v2.4.5/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <style>
        .layui-form-checkbox[lay-skin=primary] i {
            position: relative;
            top: 7px;
        }
            .layui-table-view .layui-form-radio>i {
                margin: 13px;
        }
    </style>
</head>
<body>

<div class="demoTable">
    <button class="layui-btn " data-type="isOk">确认选择</button>
</div>

<table class="layui-table" lay-data="{ url:'/SeleOrderServlet', page:false, id:'idTest'}" lay-filter="demo">
    <thead>
    <tr>
    <tr>
        <th lay-data="{type:'radio', fixed: 'left'}"></th>
        <th lay-data="{type:'numbers', width:50, fixed: 'left'}">序号</th>
        <th lay-data="{field:'consumerAccount', width:120, align:'center'}" >用户账号</th>
        <th lay-data="{field:'wareId', width:100, align:'center',toolbar: '#barDemo2' }">商品详情</th>
        <th lay-data="{field:'orderPrice', width:100, align:'center'}">订单总价</th>
        <th lay-data="{field:'orderState', width:90, align:'center',templet:'#titleTpl'}">订单状态</th>
        <th lay-data="{field:'orderRemarks', width:150, align:'center'}">订单备注</th>
        <th lay-data="{field:'orderAddress', maxwidth:300, align:'center'}">订单地址</th>
        <th lay-data="{field:'orderDate', width:180, align:'center'}">订单生成时间</th>
    </tr>
    </thead>
</table>
<script type="text/html" id="barDemo2">
    <a class="layui-btn btn layui-btn-sm" lay-event="sele">查看商品</a>
</script>
<script type="text/html" id="titleTpl">
    {{#  if(d.orderState ==0){ }}
    <a href="/detail/{{d.orderState}}" class="layui-table-link">已完成</a>
    {{#  } else if(d.orderState ==1){ }}
    <a href="/detail/{{d.orderState}}" class="layui-table-link">待付款</a>
    {{#  } else if(d.orderState ==2){ }}
    <a href="/detail/{{d.orderState}}" class="layui-table-link">待发货</a>
    {{#  } else if(d.orderState ==3){ }}
    <a href="/detail/{{orderState}}" class="layui-table-link">待收货</a>
    {{#  } else if(d.orderState ==4){ }}
    <a href="/detail/{{d.orderState}}" class="layui-table-link">待评价</a>
    {{#  } }}
</script>
<script src="../../layui-2.4/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>

    layui.use('table', function () {
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function (obj) {
            console.log(obj)
        });

        //监听单元格编辑
        table.on('edit(test)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            layer.msg('[ID: ' + data.noticeId + '] ' + field + ' 字段更改为：' + value);
        });

        var $ = layui.$, active = {
            isOk: function () {
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                var objs = eval(data);
                if (objs.length != null && "" != objs.length) {
                    var names = "";
                    var orderId="";
                    for (var j = 0; j < objs.length; j++) {
                        names = objs[j].consumerAccount ;
                        orderId = objs[j].orderId;
                    }
                    layer.confirm('用户评分账号: ' + names + ', 确认用户？', function (index) {
                        parent.document.getElementById("account").value=names;
                        parent.document.getElementById("orderId").value=orderId;
                        $.ajax({
                            url: "../../InsertEvaluateEchoServlet",
                            dataType:"json",   //返回格式为json
                            contentType:"application/json",
                            async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                            type: "get",
                            data: {"orderId":orderId},
                            success: function (msg) {
                                alert(msg);
                            }
                        });
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.layer.reload(index-1);
                    });
                } else {
                    layer.alert("至少选择一项")
                }
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });
</script>
</body>
</html>